package com.jushu.storbox.entities;

import android.content.ContentValues;
import android.database.Cursor;

import com.jushu.storbox.database.IAlbumFolderDao;
import com.jushu.storbox.database.IObjectConvert;

public class AlbumFolderInfo implements IObjectConvert {
	
	public final static int FOLDER_STATE_NOMAL = 0;
	public final static int FOLDER_STATE_DELETE = 1;
	
	private String ownerBy;

	private String folderPath;
	
	private String folderName;
	
	private String serverFolderId="";
	
	private long contentCreateAt = 0;
	
	private String serverFolderName;
	
	/**local state*/
	private int state = FOLDER_STATE_NOMAL;

	public String getOwnerBy() {
		return ownerBy;
	}

	public void setOwnerBy(String ownerBy) {
		this.ownerBy = ownerBy;
	}

	public String getFolderName() {
		return folderName;
	}

	public void setFolderName(String folderName) {
		this.folderName = folderName;
	}

	public String getFolderPath() {
		return folderPath;
	}

	public void setFolderPath(String folderPath) {
		this.folderPath = folderPath;
	}

	public String getServerFolderId() {
		return serverFolderId;
	}

	public void setServerFolderId(String serverFolderId) {
		this.serverFolderId = serverFolderId;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	public long getContentCreateAt() {
		return contentCreateAt;
	}

	public void setContentCreateAt(long contentCreateAt) {
		this.contentCreateAt = contentCreateAt;
	}

	public String getServerFolderName() {
		return serverFolderName;
	}

	public void setServerFolderName(String serverFolderName) {
		this.serverFolderName = serverFolderName;
	}

	@Override
	public void fromCursor(Cursor cursor) {
		setOwnerBy(cursor.getString(cursor.getColumnIndex(IAlbumFolderDao.OWNER_ID)));
		setFolderPath(cursor.getString(cursor.getColumnIndex(IAlbumFolderDao.FOLDER_PATH)));
		setFolderName(cursor.getString(cursor.getColumnIndex(IAlbumFolderDao.FOLDER_NAME)));
		setServerFolderId(cursor.getString(cursor.getColumnIndex(IAlbumFolderDao.SERVER_FOLDER_ID)));
		setContentCreateAt(cursor.getLong(cursor.getColumnIndex(IAlbumFolderDao.FOLDER_CREATEAT)));
		setServerFolderName(cursor.getString(cursor.getColumnIndex(IAlbumFolderDao.FOLDER_REMOTE_NAME)));
		
	}

	@Override
	public ContentValues toContentValues() {
		ContentValues cv = new ContentValues();
		cv.put(IAlbumFolderDao.OWNER_ID, getOwnerBy());
		cv.put(IAlbumFolderDao.FOLDER_PATH, getFolderPath());
		cv.put(IAlbumFolderDao.FOLDER_NAME, getFolderName());
		cv.put(IAlbumFolderDao.SERVER_FOLDER_ID, getServerFolderId());
		cv.put(IAlbumFolderDao.FOLDER_CREATEAT, getContentCreateAt());
		cv.put(IAlbumFolderDao.FOLDER_REMOTE_NAME, getServerFolderName());
		return cv;
	}

	public ContentValues getAlbumFolderCV() {
		ContentValues cv = new ContentValues();
		cv.put(IAlbumFolderDao.SERVER_FOLDER_ID, getServerFolderId());
		return cv;
	}

	@Override
	public boolean equals(Object o) {
		if(o == null || !(o instanceof AlbumFolderInfo)) {
			return false;
		} else {
			if(this == o) {
				return true;
			} else {
				AlbumFolderInfo temp = (AlbumFolderInfo) o;
				if(temp.getFolderPath().equals(folderPath)
					&& temp.getOwnerBy().equals(ownerBy)) {
					return true;
				} else {
					return false;
				}
			}
		}
	}

	@Override
	public int hashCode() {
		return folderPath.hashCode() + ownerBy.hashCode();
	}

	
}
